package com.hxkcloud.patient.activitys;


import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.utils.SharedPreferenceUtil;

public class GuideActivity extends BaseActivity {
    private PagerAdapter mPagerAdapter;
    private List<View> mListViews;
    private ViewPager mViewPager;
    private TextView ivGuide;
    private TextView mSkip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        String guide = SharedPreferenceUtil.getGuide(mContext);
        if (guide != null && guide.equals("T")) {
            Intent intent = new Intent(GuideActivity.this, LoginActivity.class);
            startActivity(intent);
            GuideActivity.this.finish();
        }
        setContentView(R.layout.activity_guide);
        mListViews = new ArrayList<View>();
        LayoutInflater inflater = getLayoutInflater();
        View view0 = inflater.inflate(R.layout.guide_item_view, null);
        ((ImageView) view0.findViewById(R.id.iv_itme_guide)).setImageResource(R.mipmap.guide_a1);
        View view1 = inflater.inflate(R.layout.guide_item_view2, null);
        ((ImageView) view1.findViewById(R.id.iv_itme_guide)).setImageResource(R.mipmap.guide_b1);
        View view2 = inflater.inflate(R.layout.guide_item_view3, null);
        mSkip = (TextView) view0.findViewById(R.id.text_skip);
        ivGuide = (TextView) view2.findViewById(R.id.text_feel);
        ((ImageView) view2.findViewById(R.id.iv_itme_guide)).setImageResource(R.mipmap.guide_c1);
        ivGuide.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                SharedPreferenceUtil.setGuide(mContext, "T");
                Intent intent = new Intent(GuideActivity.this, LoginActivity.class);
                startActivity(intent);
                GuideActivity.this.finish();
            }
        });
        mSkip.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                SharedPreferenceUtil.setGuide(mContext, "T");
                Intent intent = new Intent(GuideActivity.this, LoginActivity.class);
                startActivity(intent);
                GuideActivity.this.finish();
            }
        });
        mListViews.add(view0);
        mListViews.add(view1);
        mListViews.add(view2);
        mViewPager = (ViewPager) findViewById(R.id.guide_view_group);
        mPagerAdapter = new PagerAdapter(mListViews);
        mViewPager.setAdapter(mPagerAdapter);
    }

    @Override
    protected void updateByHandler(Message msg) {

    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    private class PagerAdapter extends android.support.v4.view.PagerAdapter {

        private List<View> mViews;

        public PagerAdapter(List<View> views) {
            super();
            mViews = views;
        }

        @Override
        public int getCount() {
            return mViews.size();
        }

        @Override
        public boolean isViewFromObject(View v, Object obj) {
            return v == obj;
        }

        @Override
        public void destroyItem(View view, int position, Object object) {
            ((ViewPager) view).removeView(mViews.get(position));
        }

        @Override
        public Object instantiateItem(View view, int position) {

            ((ViewPager) view).addView(mViews.get(position), 0);
            return mViews.get(position);
        }
    }
}
